<template>
	<view>
		<view class="demo-nav2" style="background-color: #fff;width: 100%; padding-top: 12rpx;">
			<gui-switch-navigation :items="[{id:0,name:'最新申请'},{id:1,name:'申请审核中'},{id:2,name:'审核通过'}]"
				@change="navchange2" textAlign="center" :isCenter="true" activeDirection="center" :size="0"
				activeLineBg="linear-gradient(to right, #ede844, #ede844)" activeColor="#fff" :margin="45"
				padding="30rpx" activeLineHeight="8rpx" lineHeight="65rpx"
				activeLineWidth="200rpx"></gui-switch-navigation>
		</view>

		<view style="margin: auto; width: 100%;">
			<view style="padding: 0 30rpx; margin-top: 15rpx;">
				<view class="gui-list">
					<view class="gui-list-items" style="margin: 20rpx 0;" v-for="(item, index) in show_data"
						:key="index" @tap="to_apply(item.id,item.cate_id,item.cate.name)">

						<view class="gui-card-view gui-margin-top gui-box-shadow" style="width: 100%;">
							<view class="gui-card-body gui-border-b gui-flex gui-rows gui-nowrap">
								<!-- <image src="https://graceui.oss-cn-beijing.aliyuncs.com/faces/1.png" class="gui-card-img"></image> -->
								<view class="gui-card-desc">
									<view class="gui-flex gui-rows gui-nowrap gui-align-items-center gui-border-b">
										<text class="gui-card-name">{{item.cate.name}}</text>
										<text v-if="item.status == 10" class="gui-text-small gui-color-green">已完成</text>
										<text v-else-if="item.status == 9"
											class="gui-text-small gui-color-red">已取消</text>
										<text v-else-if="item.status == 0"
											class="gui-text-small gui-color-red">未通过</text>
										<text v-else class="gui-text-small gui-color-red">待完成</text>
									</view>
									<text class="gui-card-text gui-block-text"
										style="margin-top:20rpx;">{{item.category_name}}</text>
									<!-- <text class="gui-card-text gui-block-text">139*****888</text> -->
								</view>
							</view>
							<view
								class="gui-card-footer gui-flex gui-rows gui-nowrap gui-space-between gui-align-items-center gui-border-b">
								<text class="gui-icons gui-card-footer-item gui-border-r">创建时间 :
									{{item.created_at.split(" ")[0]}}</text>
								<text class="gui-icons gui-card-footer-item">更新于 :
									{{item.updated_at.split(" ")[0]}}</text>
								<!-- <text class="gui-icons gui-card-footer-item gui-border-r">&#xe608; 店铺</text>
								<text class="gui-icons gui-card-footer-item gui-border-r">&#xe613; 设置</text>
								<text class="gui-icons gui-card-footer-item">&#xe61e; 链接</text> -->
							</view>
							<view
								class="gui-card-footer gui-flex gui-rows gui-nowrap gui-space-between gui-align-items-center">
								<text class="gui-icons gui-card-footer-item gui-border-r">&#xe62f; 查看</text>
								<text class="gui-icons gui-card-footer-item"
									@tap.stop="close_apply(item.id)">&#xe66c;取消申报</text>
							</view>
						</view>

					</view>
				</view>
			</view>
		</view>

		<view v-if="no_more" class="gui-color-gray gui-text-center" style="text-align: center; margin-top: 250rpx;">
			<text>无更多数据</text>
		</view>

		<view class=""><!-- 遮盖层 -->
			<gui-page-loading ref="guipageloading"></gui-page-loading>
		</view>
	</view>
</template>

<script>
	import loging from "@/Grace6/components/gui-page-loading.vue";
	export default {
		data() {
			return {
				no_more: false,
				pageLoading: false,
				show_data: [],
				pages: 0,
				apiLoadSta: false,
				switch_index: 0
			}
		},
		onLoad() {
			this.user = uni.getStorageSync("member");
			//console.log(this.user,'user');
		},
		onReady() {
			this.getdata();
		},
		methods: {
			close_apply(id) { //取消申报
				let self = this;
				uni.showModal({
					title: '提示',
					content: '是否要取消申报 ?',
					success(res) {
						if (res.confirm) {
							self.$refs.guipageloading.open();
							let url = '/hzj_apply/close_apply'
							let parm = {
								a_id: id
							}
							self.$boya.NPost(url, parm, function(res) {
								self.$refs.guipageloading.close();
								console.log(res, 'cols');
								if (res.code == 200) {
									if (res.data == "存在审核序列,不可取消") {
										uni.showModal({
											title: '提示',
											content: res.data,
											showCancel: false,
										});
									} else {
										uni.showToast({
											title: '取消申报 成功'
										});
										self.getdata();
									}
								} else {
									uni.showModal({
										title: '提示',
										content: res.data
									});
								}
							})
						}
					}
				});
			},
			navchange2(index) {
				this.switch_index = index;
				this.pages = 0;
				this.getdata();
			},
			to_apply(id, cate_id, cate) {
				uni.navigateTo({
					url: './apply?apply_id=' + id + '&category=' + cate_id + '&cate_name=' + cate
				})
			},
			getdata(nofirst) {
				this.apiLoadSta = true;
				if (!nofirst) {
					// console.log('这里这里：', nofirst);
					this.$refs.guipageloading.open();
					this.show_data = []
				}
				let self = this;
				// console.log('这儿pages: ', self.pages);
				uni.showLoading({
					title: '加载中...'
				});
				let url = '/hzj_apply/get_apply'
				let parm = {
					pages: self.pages,
					user_id: self.user.id,
					apply_id: 0,
					switch_index: self.switch_index
				}
				self.$boya.NPost(url, parm, function(res) {
					// console.log('shuju: ', res.data.length);
					let data = res.data
					if (data.length <= 0) {
						self.$refs.guipageloading.close();
						uni.showToast({
							title: '暂无数据',
							duration: 2000,
							icon: 'error'
						});
					} else {
						for (var i = 0; i < data.length; i++) {
							if (data[i].cate_id != 74 && data[i].cate_id != 146) {
								if (nofirst) { // 区分不是第一次
									self.show_data.push(res.data[i])
								} else {
									self.show_data.push(res.data[i])
									self.$refs.guipageloading.close();
								}
							}

							if (self.show_data.length == 0) {
								self.no_more = true;
							}

							// 加载完成后停止加载动画
							self.$refs.guipageloading.close();
							self.apiLoadSta = false;
							uni.hideLoading();
						}
						console.log('new: ', self.show_data);
					}
				})
			},
			reload() {
				let self = this;

				self.no_more = true;
				self.apiLoadSta = false;
				uni.showLoading({
					title: '加载中...'
				});
				console.log("无更多数据");
				uni.hideLoading();
				// if (this.no_more) {
				// 	self.no_more = true;
				// 	self.apiLoadSta = false;
				// uni.showLoading({
				// 	title: '加载中...'
				// });
				// 	console.log("无更多数据");
				// } else {
				// 	self.pages++;
				// 	console.log('加载更多');
				// 	self.getdata(true);
				// }
			},
		}
	}
</script>

<style>
	.gui-card-view {
		background-color: #FFFFFF;
		padding: 25rpx;
	}

	.gui-card-body {
		padding-bottom: 25rpx;
	}

	.gui-card-img {
		width: 100rpx;
		height: 100rpx;
		border-radius: 80rpx;
	}

	.gui-card-desc {
		width: 400rpx;
		margin-left: 25rpx;
		flex: 1;
	}

	.gui-card-name {
		font-size: 28rpx;
		color: #333333;
		line-height: 40rpx;
		margin-right: 20rpx;
	}

	.gui-card-text {
		line-height: 40rpx;
		font-size: 24rpx;
		color: #888888;
	}

	.gui-card-footer {
		margin-top: 25rpx;
	}

	.gui-card-footer-item {
		width: 100rpx;
		text-align: center;
		flex: 1;
		line-height: 38rpx;
		font-size: 26rpx;
		color: #666666;
	}
</style>